package com.haixiaoke.saas.repository.service.impl;

import com.haixiaoke.saas.repository.mapper.HotCityMapper;
import com.haixiaoke.saas.repository.pojo.HotCity;
import com.haixiaoke.saas.repository.service.IHotCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 热门城市Service业务层处理
 *
 * @author zhiping
 * @date 2023-04-06
 */
@Service
public class HotCityServiceImpl implements IHotCityService {
    @Autowired
    private HotCityMapper hotCityMapper;

    /**
     * 查询热门城市
     *
     * @param cityId 热门城市主键
     * @return 热门城市
     */
    @Override
    public HotCity selectHotCityByCityId(Long cityId) {
        return hotCityMapper.selectHotCityByCityId(cityId);
    }

    /**
     * 查询热门城市列表
     *
     * @param hotCity 热门城市
     * @return 热门城市
     */
    @Override
    public List<HotCity> selectHotCityList(HotCity hotCity) {
        return hotCityMapper.selectHotCityList(hotCity);
    }

    /**
     * 新增热门城市
     *
     * @param hotCity 热门城市
     * @return 结果
     */
    @Override
    public int insertHotCity(HotCity hotCity) {
        if (!checkHotCityUnique(hotCity.getCityId())) {
            throw new RuntimeException("该城市已经添加!");
        }
        hotCity.setCreateTime(new Date());
        return hotCityMapper.insertHotCity(hotCity);
    }

    /**
     * 修改热门城市
     *
     * @param hotCity 热门城市
     * @return 结果
     */
    @Override
    public int updateHotCity(HotCity hotCity) {
        hotCity.setUpdateTime(new Date());
        return hotCityMapper.updateHotCity(hotCity);
    }

    /**
     * 批量删除热门城市
     *
     * @param cityIds 需要删除的热门城市主键
     * @return 结果
     */
    @Override
    public int deleteHotCityByCityIds(Long[] cityIds) {
        return hotCityMapper.deleteHotCityByCityIds(cityIds);
    }

    /**
     * 删除热门城市信息
     *
     * @param cityId 热门城市主键
     * @return 结果
     */
    @Override
    public int deleteHotCityByCityId(Long cityId) {
        return hotCityMapper.deleteHotCityByCityId(cityId);
    }

    @Override
    public boolean checkHotCityUnique(Long cityId) {
        return hotCityMapper.checkHotCityUnique(cityId) == 0;
    }


}
